home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / atlconv.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  4.2 KB  |  109 lines

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1996-1997 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Active Template Library Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Active Template Library product.
  10.  
  11. #ifndef __ATLCONV_H__
  12.     #error atlconv.cpp requires atlconv.h to be included first
  13. #endif
  14.  
  15. #ifndef _ATL_NO_CONVERSIONS
  16. /////////////////////////////////////////////////////////////////////////////
  17. // Global UNICODE<>ANSI translation helpers
  18. LPWSTR WINAPI AtlA2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars)
  19. {
  20.     _ASSERTE(lpa != NULL);
  21.     _ASSERTE(lpw != NULL);
  22.     // verify that no illegal character present
  23.     // since lpw was allocated based on the size of lpa
  24.     // don't worry about the number of chars
  25.     lpw[0] = '\0';
  26.     MultiByteToWideChar(CP_ACP, 0, lpa, -1, lpw, nChars);
  27.     return lpw;
  28. }
  29.  
  30. LPSTR WINAPI AtlW2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars)
  31. {
  32.     _ASSERTE(lpw != NULL);
  33.     _ASSERTE(lpa != NULL);
  34.     // verify that no illegal character present
  35.     // since lpa was allocated based on the size of lpw
  36.     // don't worry about the number of chars
  37.     lpa[0] = '\0';
  38.     WideCharToMultiByte(CP_ACP, 0, lpw, -1, lpa, nChars, NULL, NULL);
  39.     return lpa;
  40. }
  41.  
  42. #ifdef _WINGDI_
  43.  
  44. // don't include this code when building DLL
  45. LPDEVMODEW AtlDevModeA2W(LPDEVMODEW lpDevModeW, LPDEVMODEA lpDevModeA)
  46. {
  47.     if (lpDevModeA == NULL)
  48.         return NULL;
  49.     _ASSERTE(lpDevModeW != NULL);
  50.     AtlA2WHelper(lpDevModeW->dmDeviceName, (LPCSTR)lpDevModeA->dmDeviceName, 32*sizeof(WCHAR));
  51.     memcpy(&lpDevModeW->dmSpecVersion, &lpDevModeA->dmSpecVersion,
  52.         offsetof(DEVMODEW, dmFormName) - offsetof(DEVMODEW, dmSpecVersion));
  53.     AtlA2WHelper(lpDevModeW->dmFormName, (LPCSTR)lpDevModeA->dmFormName, 32*sizeof(WCHAR));
  54.     memcpy(&lpDevModeW->dmLogPixels, &lpDevModeA->dmLogPixels,
  55.         sizeof(DEVMODEW) - offsetof(DEVMODEW, dmLogPixels));
  56.     if (lpDevModeA->dmDriverExtra != 0)
  57.         memcpy(lpDevModeW+1, lpDevModeA+1, lpDevModeA->dmDriverExtra);
  58.     lpDevModeW->dmSize = sizeof(DEVMODEW);
  59.     return lpDevModeW;
  60. }
  61.  
  62. LPTEXTMETRICW AtlTextMetricA2W(LPTEXTMETRICW lptmW, LPTEXTMETRICA lptmA)
  63. {
  64.     if (lptmA == NULL)
  65.         return NULL;
  66.     _ASSERTE(lptmW != NULL);
  67.     memcpy(lptmW, lptmA, sizeof(LONG) * 11);
  68.     memcpy(&lptmW->tmItalic, &lptmA->tmItalic, sizeof(BYTE) * 5);
  69.     MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&lptmA->tmFirstChar, 1, &lptmW->tmFirstChar, 1);
  70.     MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&lptmA->tmLastChar, 1, &lptmW->tmLastChar, 1);
  71.     MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&lptmA->tmDefaultChar, 1, &lptmW->tmDefaultChar, 1);
  72.     MultiByteToWideChar(CP_ACP, 0, (LPCSTR)&lptmA->tmBreakChar, 1, &lptmW->tmBreakChar, 1);
  73.     return lptmW;
  74. }
  75.  
  76. LPTEXTMETRICA AtlTextMetricW2A(LPTEXTMETRICA lptmA, LPTEXTMETRICW lptmW)
  77. {
  78.     if (lptmW == NULL)
  79.         return NULL;
  80.     _ASSERTE(lptmA != NULL);
  81.     memcpy(lptmA, lptmW, sizeof(LONG) * 11);
  82.     memcpy(&lptmA->tmItalic, &lptmW->tmItalic, sizeof(BYTE) * 5);
  83.     WideCharToMultiByte(CP_ACP, 0, &lptmW->tmFirstChar, 1, (LPSTR)&lptmA->tmFirstChar, 1, NULL, NULL);
  84.     WideCharToMultiByte(CP_ACP, 0, &lptmW->tmLastChar, 1, (LPSTR)&lptmA->tmLastChar, 1, NULL, NULL);
  85.     WideCharToMultiByte(CP_ACP, 0, &lptmW->tmDefaultChar, 1, (LPSTR)&lptmA->tmDefaultChar, 1, NULL, NULL);
  86.     WideCharToMultiByte(CP_ACP, 0, &lptmW->tmBreakChar, 1, (LPSTR)&lptmA->tmBreakChar, 1, NULL, NULL);
  87.     return lptmA;
  88. }
  89.  
  90. LPDEVMODEA AtlDevModeW2A(LPDEVMODEA lpDevModeA, LPDEVMODEW lpDevModeW)
  91. {
  92.     if (lpDevModeW == NULL)
  93.         return NULL;
  94.     _ASSERTE(lpDevModeA != NULL);
  95.     AtlW2AHelper((LPSTR)lpDevModeA->dmDeviceName, lpDevModeW->dmDeviceName, 32*sizeof(char));
  96.     memcpy(&lpDevModeA->dmSpecVersion, &lpDevModeW->dmSpecVersion,
  97.         offsetof(DEVMODEA, dmFormName) - offsetof(DEVMODEA, dmSpecVersion));
  98.     AtlW2AHelper((LPSTR)lpDevModeA->dmFormName, lpDevModeW->dmFormName, 32*sizeof(char));
  99.     memcpy(&lpDevModeA->dmLogPixels, &lpDevModeW->dmLogPixels,
  100.         sizeof(DEVMODEA) - offsetof(DEVMODEA, dmLogPixels));
  101.     if (lpDevModeW->dmDriverExtra != 0)
  102.         memcpy(lpDevModeA+1, lpDevModeW+1, lpDevModeW->dmDriverExtra);
  103.     lpDevModeA->dmSize = sizeof(DEVMODEA);
  104.     return lpDevModeA;
  105. }
  106.  
  107. #endif //_WINGDI_
  108. #endif //!_ATL_NO_CONVERSIONS
  109.